package com.lvtu.monitor.utils;

import java.io.IOException;
import java.util.Properties;

/**
 * 
 * @ClassName: Constants
 * @Description: 全局常量
 * @author qinzubo
 * @date 2014-11-2 下午2:28:53
 * 
 */
public final class Constants {
	
	/** 异常日志的elastic索引名称 */
	public static final String ELASTIC_INDEX_EX_TRACE = "ex-trace-index";
	
	/** 异常日志的elastic索引类型 */
	public static final String ELASTIC_TYPE_EX_TRACE = "exception";
	
	/** nginx日志的elastic索引名称 */
	public static final String ELASTIC_INDEX_NGX_LOG = "ngxlog-from-redis";
	
	/** 全部监控规则的缓存key */
	public static final String KEY_ALL_EX_PATTERNS = "lvtu_monitor_ex_patterns";

	private static Properties properties;
	private static volatile Constants instance=null;
	
	
	private Constants(){
		init();
	}
	

	private void init() {
		try {
			properties = new Properties();
			properties.load(getClass().getResourceAsStream("/const.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Constants getInstance() {
		if (instance == null) {
			synchronized (Constants.class) {
				if(instance==null){					
					instance = new Constants();
				}
			}
		}
		return instance;
	}
	
	
	public String getProperty(String key) {
		return getValue(key);
	}

	/**
	 * 获取属性
	 * 
	 * @return
	 */
	public String getValue(String key) {
		return System.getProperty(key) != null?System.getProperty(key):properties.getProperty(key);
	}
	
}
